﻿using AppData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace AppData
{
    public partial class User //: ISerialize
    {
        private long m_Id;
        /// <summary>
        /// id
        /// </summary>
        public long id { get { return m_Id; } }

        public string name => miniUserInfo.name;

        private string m_Token = "";
        /// <summary>
        /// 用于断线重连
        /// </summary>
        public string token { get { return m_Token; } }

        /// <summary>
        /// 普通的货币
        /// </summary>
        private int m_Coin;
        public int coin { get { return m_Coin; } }

        /// <summary>
        /// 付费的货币
        /// </summary>
        private int m_Diamond;
        public int diamond { get { return m_Diamond; } }


        ///// <summary>
        ///// 充值次数
        ///// </summary>
        //int m_ChargedTimes;
        //public bool hasCharged => m_ChargedTimes > 0;

        /// <summary>
        /// home界面广告播放次数
        /// </summary>
        private int m_HomeAdTimesRemain;
        public int homeAdTimesRemain
        {
            get { return m_HomeAdTimesRemain; }
            set { m_HomeAdTimesRemain = value; }
        }

        /// <summary>
        /// 等级
        /// </summary>
        private int m_Level;
        public int level => m_Level;

        /// <summary>
        /// 是否是机器人
        /// </summary>
        private bool m_IsRobot;
        public bool isRobot => m_IsRobot;

        /// <summary>
        /// 到达过的最大等级
        /// </summary>
        private int m_MaxLv;
        public int maxLv
        {
            get { return m_MaxLv; }
            set { m_MaxLv = value; }
        }

        /// <summary>
        /// 登陆天数
        /// </summary>
        private int m_LoginedDay;
        public int loginedDay
        {
            get
            {
                if (m_LoginedDay < 0) m_LoginedDay = 1;
                return m_LoginedDay;
            }
        }

        /// <summary>
        /// 已领取的登陆奖励
        /// </summary>
        private List<int> m_ObtainLoginBonus;
        public List<int> obtainLoginBonus
        {
            get => m_ObtainLoginBonus;
        }

        public const int maxObtainLoginBonusDay = 30;

        /// <summary>
        /// 已获取分享奖励
        /// </summary>
        int m_ObtainShareReward;
        public int obtainShareReward
        {
            get => m_ObtainShareReward;
            set => m_ObtainShareReward = value;
        }

        protected long m_MemberTimeEndDate;
        public long memberTimeEndDate => m_MemberTimeEndDate;

        private List<Moment> m_Moments = new List<Moment>();
        public List<Moment> moments { get => m_Moments; set => m_Moments = value; }


        List<long> m_Friends = new List<long>();
        public List<long> friends => m_Friends;

        public List<long> myFollows = new List<long>();
        public List<long> followers = new List<long>();

        public MiniUserInfo miniUserInfo;


        public User()
        {

        }

        public static Action<int> onUpdateDiamond;

        public void UpdateDiamond(int diamond)
        {
            m_Diamond = diamond;

            onUpdateDiamond?.Invoke(diamond);
        }

        public void AddFriend(long friend)
        {
            if (m_Friends == null)
                m_Friends = new List<long>();

            if (!this.m_Friends.Contains(friend))
                m_Friends.Add(friend);
        }
        public void AddMyFollow(long targetUser)
        {
            if (this.myFollows == null)
                myFollows = new List<long>();

            if (!this.myFollows.Contains(targetUser))
                myFollows.Add(targetUser);
        }
        public void RemoveMyFollow(long targetUser)
        {
            if (this.myFollows != null)
                myFollows.Remove(targetUser);
        }
        public void RemoveFollower(long targetUser)
        {
            if (this.followers != null)
                followers.Remove(targetUser);
        }
        public void AddFollower(long targetUser)
        {
            if (this.followers == null)
                followers = new List<long>();

            if (!this.followers.Contains(targetUser))
                followers.Add(targetUser);
        }
       

        public void AddMoment(Moment moment)
        {
            if (this.m_Moments == null)
                m_Moments = new List<Moment>();

            m_Moments.Add(moment);
        }
    }
}
